﻿using System;
using System.Data;
using Oracle.DataAccess.Client;
using Platform.Configuration;

namespace Entity
{
    public class BaseDBHelper
    {
        private static readonly string connStr = ConfigHelper.PlatformConnString;

        public static DataSet RunSearch(string cmdText, OracleParameter[] storedParams)
        {
            var dt = new DataSet();
            using (var conn = new OracleConnection(connStr))
            {
                OracleTransaction tran = null;
                try
                {
                    var cmd = new OracleCommand(cmdText, conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    conn.Open();
                    tran = conn.BeginTransaction(IsolationLevel.ReadCommitted);
                    cmd.Transaction = tran;
                    for (var i = 0; i < storedParams.Length; i++)
                        cmd.Parameters.Add(storedParams[i]);
                    var ada = new OracleDataAdapter(cmd);
                    ada.Fill(dt);
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
            return dt;
        }
    }
}